/**
 * MarioCamera
 * @extends Camera
 * @version 2010.12.03
 */

class MarioCamera extends Camera;

/**
 * UpdateViewTarget - This function was extended from camera. The Pawn
 * this is attached to (i.e. the player) will request a camera type when
 * it is created with the function GetDefaultCameraMode.
 * @version 2010.12.03
 */
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)
{
	local Vector        Loc, Pos, HitLocation, HitNormal;
	local Rotator       Rot;
	local Actor         HitActor;
	local CameraActor   CamActor;
	local bool          bDoNotApplyModifiers;
	local TPOV          OrigPOV;


	`log("oh yeah!");


	//store previous POV, in case we need it later
	OrigPOV = OutVT.POV;

	//Default FOV on viewtarget
	OutVT.POV.FOV = DefaultFOV;

	//Viewing through a camera actor.
	CamActor = CameraActor(OutVT.Target);
	if(CamActor != None)
	{
		CamActor.GetCameraView(DeltaTime, OutVT.POV);

		//Grab aspect ratio from the CameraActor.
		bConstrainAspectRatio   = bConstrainAspectRatio || CamActor.bConstrainAspectRatio;
		OutVT.AspectRatio       = CamActor.AspectRatio;

		//See if the CameraActor wants to override the PostProcess settings used.
		CamOverridePostProcessAlpha = CamActor.CamOverridePostProcessAlpha;
		CamPostProcessSettings      = CamActor.CamOverridePostProcess;
	}
	else
	{
		//Give Pawn Viewtarget a chance to dictate the camera position.
		//If Pawn doesn't override the camera view, then we proceed with our own defaults
		if(Pawn(OutVT.Target) == None ||
		  !Pawn(OutVT.Target).CalcCamera(DeltaTime, OutVT.POV.Location, OutVT.POV.Rotation, OutVT.POV.FOV))
		{
			//Don't apply modifiers when using these debug camera modes.
			bDoNotApplyModifiers = TRUE;

			switch(CameraStyle)
			{
			//Do not update, keep previous camera position by restoring
			case 'Fixed':
				//Saved POV, in case CalcCamera changes it but still returns false
				OutVT.POV = OrigPOV;
				break;
			
			//Simple third person view implementation
			case 'ThirdPerson':
			case 'FreeCam':
			case 'FreeCam_Default':
				Loc = OutVT.Target.Location;
				Rot = OutVT.Target.Rotation;
				
				//OutVT.Target.GetActorEyesViewPoint(Loc, Rot);
				if(CameraStyle == 'FreeCam' || CameraStyle == 'FreeCam_Default')
					Rot = PCOwner.Rotation;

				Loc += FreeCamOffset >> Rot;
				Pos  = Loc - Vector(Rot) * FreeCamDistance;

				//@fixme, respect BlockingVolume.bBlockCamera=false
				HitActor = Trace(HitLocation, HitNormal, Pos, Loc, FALSE, vect(12,12,12));
				OutVT.POV.Location = (HitActor == None) ? Pos : HitLocation;
				OutVT.POV.Rotation = Rot;
				break;
			
			case 'small':
				Rot = PCOwner.Rotation;
				Loc.X = PCOwner.Pawn.Location.X;
				Loc.Y = PCOwner.Pawn.Location.Y;
				Loc.Z = PCOwner.Pawn.Location.Z+800;
				Pos = Loc - Vector(Rot);// * FreeCamDistance;

				OutVT.POV.Location = Pos;
				OutVT.POV.Rotation = Rot;
				break;
			
			case 'big':
				Rot = PCOwner.Rotation;
				Loc.X = PCOwner.Pawn.Location.X;
				Loc.Y = PCOwner.Pawn.Location.Y;
				Loc.Z = PCOwner.Pawn.Location.Z + 400;
				Pos = Loc - Vector(Rot);// * FreeCamDistance;

				OutVT.POV.Location = Pos;
				OutVT.POV.Rotation = Rot;
				break;

			case 'third':
				Rot.Pitch = (-40.0f     *DegToRad) * RadToUnrRot;
				Rot.Roll =  (0          *DegToRad) * RadToUnrRot;
				Rot.Yaw =   (10.0f      *DegToRad) * RadToUnrRot;

	
				Loc.X = PCOwner.Pawn.Location.X - 250;
				Loc.Y = PCOwner.Pawn.Location.Y;
				Loc.Z = PCOwner.Pawn.Location.Z + 400;

				Pos = Loc - Vector(Rot);// * FreeCamDistance;

				OutVT.POV.Location = Pos;
				OutVT.POV.Rotation = Rot;
				break;

			 //Simple first person, view through viewtarget's 'eyes'
			case 'FirstPerson':
			default:       
				OutVT.Target.GetActorEyesViewPoint(OutVT.POV.Location, OutVT.POV.Rotation);
				break;
			}
		}
	}

	if(!bDoNotApplyModifiers )
		//Apply camera modifiers at the end (view shakes for example)
		ApplyCameraModifiers(DeltaTime, OutVT.POV);

	//`log( WorldInfo.TimeSeconds  @ GetFuncName() @ OutVT.Target @ OutVT.POV.Location @ OutVT.POV.Rotation @ OutVT.POV.FOV );
}

defaultproperties
{
	DefaultFOV = 90.0;
}

